package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.ClassInstructorTeacherMapper;
import com.zhentao.pojo.ClassInstructorTeacher;
import com.zhentao.service.ClassInstructorTeacherService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author hp
* @description 针对表【class_instructor_teacher】的数据库操作Service实现
* @createDate 2025-07-09 15:28:47
*/
@Service
public class ClassInstructorTeacherServiceImpl extends ServiceImpl<ClassInstructorTeacherMapper, ClassInstructorTeacher>
    implements ClassInstructorTeacherService{

    @Override
    @Transactional
    public boolean updateClassBinding(Integer classId, Integer newTeacherId, Integer newInstructorId) {
        // 1. 先删除该班级的现有绑定关系
        QueryWrapper<ClassInstructorTeacher> deleteWrapper = new QueryWrapper<>();
        deleteWrapper.eq("class_id", classId);
        this.remove(deleteWrapper);
        
        // 2. 创建新的绑定关系
        ClassInstructorTeacher newBinding = new ClassInstructorTeacher();
        newBinding.setClassId(classId);
        newBinding.setTeacherId(newTeacherId);
        newBinding.setInstructorId(newInstructorId);
        
        return this.save(newBinding);
    }
    
    @Override
    public ClassInstructorTeacher getBindingByClassId(Integer classId) {
        QueryWrapper<ClassInstructorTeacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("class_id", classId);
        return this.getOne(queryWrapper);
    }
}




